package com.wf.netty.coder.complex;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * string转为int
 *
 * @author wf
 * @since 2022/5/27
 */
public class String2IntegerEncoder extends MessageToByteEncoder<String> {
    @Override
    protected void encode(ChannelHandlerContext ctx, String msg, ByteBuf out) throws Exception {
        char[] chars = msg.toCharArray();
        for (char c : chars) {
            if (c >= 48 && c <= 57) {
                out.writeInt(c);
            }
        }
    }
}
